<template>
	<view class="view_desc_card">
		<view class="card_empty" v-if="!Object.keys(data || {}).length">
			<text>{{$t('erp.noProductInfo')}}~</text>
		</view>
		<view v-else class="card_main" >
			<image class="card_img" :src="data['goods_img']" />
			<view class="card_info">
				<view class="card_title">{{ data['goods_name'] }}</view>
				<view class="card_list">
					<template v-for="(item,index) in cols">
						<view v-if="!item.show || item.show(data)" :key="index" class="card_item">
							<text class="item_label">{{ item.label }}</text>
							<text class="item_desc">{{data[item.key]}}</text>
						</view>
					</template>
				</view>
			</view>
		</view>
		<view v-if="btn" class="card_bottom">
      <button type="warn" @click="goDel">{{ $t('common.del')}}</button>
			<button type="primary" @click="goEnter">{{ $t('common.enter') }}</button>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			btn:{
				type:Boolean,
				default:true,
			},
			data:{
				type:Object,
				default:()=>{
					return {}
				}
			}
		},
		emits:['del','enter'],
		data() {
			return {
				cols:[
					{
						label:this.$t('erp.productClass'),
						key:'category_name'
					},
					{
						show(row){
							return !!row.quantity
						},
						label:this.$t('erp.productNumber'),
						key:'quantity'
					},
					{
						label:this.$t('erp.productCode'),
						key:'goods_code'
					}
				]
				
			};
		},
		methods:{
			goDel(){
				this.$emit('del')
			},
			goEnter(){
				this.$emit('enter')
			},
		}
	}
</script>

<style lang="scss">
.view_desc_card{
	width: 100%;
	height: auto;
	padding: 0 25rpx 0rpx;
	.card_empty{
		min-height: 240rpx;
		padding: 40rpx;
		text-align: center;
		color: #999;
	}
	.card_main{
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
		padding-bottom: 25rpx;
		.card_img{
			width: 200rpx;
			height: 200rpx;
			object-fit: cover;
			border-radius: 10rpx;
			border: 1px solid #ddd;
		}
		.card_info{
			width: calc(100% - 200rpx - 25rpx);
			height: 100%;
			min-height: 200rpx;
			margin-left: 25rpx;
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			// justify-content: space-between;

		}
	}
	.card_title{
		font-size: 28rpx;
		color: #333;
		text-align: justify;
		line-height: 38rpx;
		margin-bottom: 20rpx;
	}
	.card_list{
		width: 100%;
		height: auto;
		.card_item{
			font-size: 26rpx;
			color: #999;
			text-align: justify;
			line-height: 34rpx;
			.item_label{
				display: inline-block;
				width: 4.5em;
				font-size: 26rpx;
				color: #333;
			}
			&+.card_item{
				margin-top: 10rpx;
			}
		}
	}
	.card_bottom{
		width: 100%;
		height: auto;
		border-top: 1rpx solid #dcdcdc;
		padding: 20rpx 30rpx;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		font-size: 24rpx;
		color: #666;
		line-height: 34rpx;
		text-align: justify;
		button{
			min-width: 140rpx;
			height: 60rpx;
			font-size: 24rpx;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-left: unset;
			margin-right: unset;
			&+button{
				margin-left: 20rpx;
			}
			&.error{
				background: red;
				color: #fff;
			}
		}
	}
}

</style>
